<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: Category.php 2870 2010-05-17 03:04:13Z huuphuoc $
 * @since        2.0.5
 */

class Shop_Models_Dao_Pdo_Mysql_CategoryContent
    extends Tomato_Model_Dao
    implements Shop_Models_Interface_CategoryContent
{
    public function convert($entity)
    {
        return new Shop_Models_CategoryContent($entity);
    }
    public function addContent($category_content)
    {
        $data = array(
            'category_id'        => $category_content->category_id,
            'language_code'               => $category_content->language_code,
            'category_content_name'               => $category_content->category_content_name,
            'category_content_friendly_url'    => $category_content->category_content_friendly_url,
            'category_content_description'           => $category_content->category_content_description
        );

        $this->_conn->insert($this->_prefix.'shop_category_content', $data);
        return $this->_conn->lastInsertId($this->_prefix.'shop_category_content');
    }
    public function getCategoryContentByCategoryId($category_id, $order = null){
        $select = $this->_conn
                        ->select()
                        ->from(array('cc' => $this->_prefix.'shop_category_content'))
                        ->joinLeft(array('l' => $this->_prefix.'language_key'), 'cc.language_code = l.language_code', array('language_name'))
                        ->where('cc.category_id = ?', $category_id);
                        if($order != null){
                            $select->order($order);
                        }
        $rs = $select->query()->fetchAll();
        return new Tomato_Model_RecordSet($rs, $this);
    }
    public function editContent($category_content, $category_content_id){
        $data = array(
            'category_id'        => $category_content->category_id,
            'language_code'               => $category_content->language_code,
            'category_content_name'               => $category_content->category_content_name,
            'category_content_friendly_url'    => $category_content->category_content_friendly_url,
            'category_content_description'           => $category_content->category_content_description
        );
        $where[] = 'category_content_id = '.$this->_conn->quote($category_content_id);
        $this->_conn->update($this->_prefix.'shop_category_content', $data, $where);
    }
}
